using System;
using System.Collections.Generic;
using System.Linq;
using Firestarter.DB_DomainModel.Logic.Test.DBChangesImporterTests;
using FireStarterModeller.BO;
using FireStarterModeller.Logic;
using FireStarterModeller.Test;
using FireStarterModeller.Test.BO;
using Habanero.Base;
using Habanero.BO.ClassDefinition;
using NUnit.Framework;
using Rhino.Mocks;

namespace Firestarter.DB_DomainModel.Logic.Test
{
    [TestFixture]
    public class TestDBToDMImporterFactory : TestBase
    {
        [Test]
        public void Test_Construct()
        {
            //---------------Set up test pack-------------------
            var relationshipNameGenerator = MockRepository.GenerateStub<IRelationshipNameGenerator>();
            var propertyTypeMapper = MockRepository.GenerateStub<IDBTypeToDMPropertyTypeMapper>();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var dbToDMImporterFactory = new DBToDMImporterFactory(propertyTypeMapper, relationshipNameGenerator);
            //---------------Test Result -----------------------
            Assert.IsNotNull(dbToDMImporterFactory);
        }

        [Test]
        public void Test_Construct_WhenNullRelationshipNameGenerator_ShouldThrowError()
        {
            //---------------Set up test pack-------------------
            IRelationshipNameGenerator relationshipNameGenerator = null;
            var propertyTypeMapper = MockRepository.GenerateStub<IDBTypeToDMPropertyTypeMapper>();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                new DBToDMImporterFactory(propertyTypeMapper, relationshipNameGenerator);
                Assert.Fail("expected ArgumentNullException");
            }
                //---------------Test Result -----------------------
            catch (ArgumentNullException ex)
            {
                StringAssert.Contains("Value cannot be null", ex.Message);
                StringAssert.Contains("relationshipNameGenerator", ex.ParamName);
            }
        }

        [Test]
        public void Test_Construct_WhenpropertyTypeMapperIsNull_ShouldThrowError()
        {
            //---------------Set up test pack-------------------
            var relationshipNameGenerator = MockRepository.GenerateStub<IRelationshipNameGenerator>();
            IDBTypeToDMPropertyTypeMapper propertyTypeMapper = null;
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                new DBToDMImporterFactory(propertyTypeMapper, relationshipNameGenerator);
                Assert.Fail("expected ArgumentNullException");
            }
                //---------------Test Result -----------------------
            catch (ArgumentNullException ex)
            {
                StringAssert.Contains("Value cannot be null", ex.Message);
                StringAssert.Contains("dmPropertyTypeMapper", ex.ParamName);
            }
        }

        [Test]
        public void Test_CreateDBChangesImporter_ShouldRetImporter()
        {
            //---------------Set up test pack-------------------
            var relationshipNameGenerator = MockRepository.GenerateStub<IRelationshipNameGenerator>();
            var propertyTypeMapper = MockRepository.GenerateStub<IDBTypeToDMPropertyTypeMapper>();
            var dbToDMImporterFactory = new DBToDMImporterFactory(propertyTypeMapper, relationshipNameGenerator);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IDBChangesImporter dbChangesImporter = dbToDMImporterFactory.CreateDBChangesImporter();
            //---------------Test Result -----------------------
            Assert.IsNotNull(dbChangesImporter);
            Assert.IsInstanceOf(typeof(DBChangesImporter), dbChangesImporter);
        }

        [Test]
        public void Test_CreateDBtoDMClassImporter_ShouldRetImporter()
        {
            //---------------Set up test pack-------------------
            var relationshipNameGenerator = MockRepository.GenerateStub<IRelationshipNameGenerator>();
            var propertyTypeMapper = MockRepository.GenerateStub<IDBTypeToDMPropertyTypeMapper>();
            var dbToDMImporterFactory = new DBToDMImporterFactory(propertyTypeMapper, relationshipNameGenerator);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var dbChangesImporter = dbToDMImporterFactory.CreateDBToDMClassImporter();
            //---------------Test Result -----------------------
            Assert.IsNotNull(dbChangesImporter);
            Assert.IsInstanceOf(typeof(DBToDMClassImporter), dbChangesImporter);
        }
        [Test]
        public void Test_CreateDBtoDMPropertyImporter_ShouldRetImporter()
        {
            //---------------Set up test pack-------------------
            var relationshipNameGenerator = MockRepository.GenerateStub<IRelationshipNameGenerator>();
            var propertyTypeMapper = MockRepository.GenerateStub<IDBTypeToDMPropertyTypeMapper>();
            var dbToDMImporterFactory = new DBToDMImporterFactory(propertyTypeMapper, relationshipNameGenerator);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var dbChangesImporter = dbToDMImporterFactory.CreateDBToDMPropertyImporter();
            //---------------Test Result -----------------------
            Assert.IsNotNull(dbChangesImporter);
            Assert.IsInstanceOf(typeof(DBToDMPropertyImporter), dbChangesImporter);
        }
        [Test]
        public void Test_CreateDBtoDMObjectIdentityImporter_ShouldRetImporter()
        {
            //---------------Set up test pack-------------------
            var relationshipNameGenerator = MockRepository.GenerateStub<IRelationshipNameGenerator>();
            var propertyTypeMapper = MockRepository.GenerateStub<IDBTypeToDMPropertyTypeMapper>();
            var dbToDMImporterFactory = new DBToDMImporterFactory(propertyTypeMapper, relationshipNameGenerator);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var dbChangesImporter = dbToDMImporterFactory.CreateDBToDMObjectIdentityImporter();
            //---------------Test Result -----------------------
            Assert.IsNotNull(dbChangesImporter);
            Assert.IsInstanceOf(typeof(DBToDMObjectIdentityImporter), dbChangesImporter);
        }
        [Test]
        public void Test_CreateDBtoDMUniqueConstraintImporter_ShouldRetImporter()
        {
            //---------------Set up test pack-------------------
            var relationshipNameGenerator = MockRepository.GenerateStub<IRelationshipNameGenerator>();
            var propertyTypeMapper = MockRepository.GenerateStub<IDBTypeToDMPropertyTypeMapper>();
            var dbToDMImporterFactory = new DBToDMImporterFactory(propertyTypeMapper, relationshipNameGenerator);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var dbChangesImporter = dbToDMImporterFactory.CreateDBToDMUniqueConstraintImporter();
            //---------------Test Result -----------------------
            Assert.IsNotNull(dbChangesImporter);
            Assert.IsInstanceOf(typeof(DBToDMUniqueConstraintImporter), dbChangesImporter);
        }
        [Test]
        public void Test_CreateDBtoDMRelationshipImporter_ShouldRetImporter()
        {
            //---------------Set up test pack-------------------
            var relationshipNameGenerator = MockRepository.GenerateStub<IRelationshipNameGenerator>();
            var propertyTypeMapper = MockRepository.GenerateStub<IDBTypeToDMPropertyTypeMapper>();
            var dbToDMImporterFactory = new DBToDMImporterFactory(propertyTypeMapper, relationshipNameGenerator);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var dbChangesImporter = dbToDMImporterFactory.CreateDBToDMRelationshipImporter();
            //---------------Test Result -----------------------
            Assert.IsNotNull(dbChangesImporter);
            Assert.IsInstanceOf(typeof(DBToDMRelationshipImporter), dbChangesImporter);
        }
    }
}